#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<functional>

namespace sbh
{
	template<class T>
	struct less
	{
		bool operator()(const T& x, const T& y)
		{
			return x < y;
		}
	};

	template<class T>
	struct greater
	{
		bool operator()(const T& x, const T& y)
		{
			return x > y;
		}
	};

	template<class T,class Container = std::vector<T>,class Compare = sbh::less<T>>
	class priority_queue
	{
	public:
		priority_queue()
			:_c()
		{}

		template <class InputIterator>

		priority_queue(InputIterator first, InputIterator last)
			:_c(first,last)
		{
			int count = _c.size();
			int root = ((count - 2) >> 1);
			for(;root>=0;root--)
			{
				AdjustDown(root);
			}
		}

		bool empty() const
		{
			return _c.empty();
		}

		size_t size() const
		{
			return _c.size();
		}

		const T& top() const
		{
			return _c.front();
		}

		void push(const T& x)
		{
			_c.push_back(x);
			AdjustUp(_c.size() - 1);
		}

		void pop()
		{
			if (_c.empty())
				return;
			std::swap(_c.front(), _c.back());
			_c.pop_back();
			AdjustDown(0);
		}

		void AdjustUp(int child)
		{
			int parent = ((child - 1) >> 1);
			while (child)
			{
				if (_com(_c[parent], _c[child]))
				{
					std::swap(_c[parent], _c[child]);
					child = parent;
					parent = ((child - 1) >> 1);
				}
				else
				{
					return;
				}
			}
		}

		void AdjustDown(int parent)
		{
			int child = parent * 2 + 1;
			while (child<_c.size())
			{
				if (child + 1 < _c.size() && _com(_c[child], _c[child + 1]))
					child += 1;
				if (_com(_c[parent], _c[child]))
				{
					std::swap(_c[parent], _c[child]);
					parent = child;
					child = parent * 2 + 1;
				}
				else
				{
					return;
				}
			}
		}

	private:
		Container _c;
		Compare _com;
	};
}